<?php 
class admin extends show
{
    public function __construct()
    {
        date_default_timezone_set('PRC');
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/dbli.class.php';
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/NumForChek.class.php';
        session_start();
    }
    public function login()
    {
        $this->display();
    }
    
    public function hcode()
    {
        $code=new NumForChek();
        $code->doimg();
        $codes=$code->getCode();
        $_SESSION['code']=$codes;
    }
    
    public function sxf()
    {
        $this->cuser();
        $this->display();
    }
    
    public function logined()
    {
    
       $uname=htmlspecialchars($_POST['manage']);
       $pass=htmlspecialchars($_POST['pass']);
       $code=is_numeric($_POST['code'])?$_POST['code']:0;
       if($code!=$_SESSION['code']){
           die('验证码不正确');
       }
       $db=new dbli($GLOBALS['C']);
       $sql="select * from `wx_admin` where uname='$uname'";
       $umessage=$db->select($sql);
       if(!$umessage){
           die('账号不存在');
       }
       if($umessage[0]['pass']!=md5($pass)){
           die('密码不正确');
       }
       $ip=$this->GetIP();
       $sql="update `wx_admin` set logip='$ip' where id={$umessage[0]['id']}";
       $db->U_D($sql);
       $_SESSION['u']=$umessage[0];
       die('ok');
    }
    
   public function checkip(){
       $ip=$this->GetIP();
       $sql="select * from `wx_admin` where id={$_SESSION['u']['id']}";
       $db=new dbli($GLOBALS['C']);
       $user=$db->select($sql);
       if($ip!=$user[0]['logip']){
           $_SESSION['u']='';
           die('注意：你被IP'.$user[0]['logip'].'踢下线了！！，请联系开发者修改密码');
       }else{
           die('1');
       }
   }
    
    
    
   public function GetIP(){
        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
            $cip = $_SERVER["HTTP_CLIENT_IP"];
        }
        elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        }
        elseif(!empty($_SERVER["REMOTE_ADDR"])){
            $cip = $_SERVER["REMOTE_ADDR"];
        }
        else{
            $cip = "无法获取！";
        }
        return $cip;
    }
    
    
    
    
    
    
    public function cuser()
    {
       isset($_SESSION['u']['id'])?'':header('Location: /?G=admin/login');
    }
    
    public function main(){
        $this->cuser();
        
        $this->display();
    }
    
    public function logout()
    {
        $_SESSION['u']='';
        header('Location: /?G=admin/login');
    }
    public function user(){
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $t = $_GET['t'] ? $_GET['t'] : 0;
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $num = 10;
        $sql = "select * from `wx_manage` where 1=1";
        if($t){$sql.= " and ( ID='$t' or nickname='$t')";}
        $sql .= ' order by ID desc limit ' . ($p - 1) * $num . ', ' . $num;
        $data = $db->select($sql);
        $countsql = "select count(ID) as nu from `wx_manage` where 1=1 ";
        if($t){$countsql.= " and ( 'ID'='$t' or 'nickname'='$t')";}
        $coutdata = $db->select($countsql);
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    public function udel()
    {
        $this->cuser();
        $uid=is_numeric($_GET['uid'])?$_GET['uid']:die('请继续乱搞');
        $db = new dbli($GLOBALS['C']);
        $sql="DELETE FROM `wx_manage` WHERE ID=$uid";
        if($db->U_D($sql)){
            $this->assign('message','删除成功。');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','删除失败。');
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    public function userup()
    {
        $this->cuser();
        $this->display();
    }
    
    public function upmoney()
    {
        $this->cuser();
        $u=$_POST['u'];
        $bh=str_replace('WKF', '', $_POST['bh']);
        $j=intval($_POST['je']);
        $db=new dbli($GLOBALS['C']);
        $sql="select * from wx_manage where ID=$bh";
        $arr=$db->select($sql);
        
        if(!$arr){
           die('玩家不存在'); 
        }
        if($u==1){
            $str="玩家「{$arr[0]['nickname']}」上分已受理，请注意查看点数，谢谢！";
            $n=$arr[0]['money']+$j;
            $db->U_D('START TRANSACTION');
            $sql1="UPDATE `wx_manage` SET `money`=$n WHERE ID=$bh";
            $sql2="INSERT INTO `user_log`(`uid`, `money`, `old_money`, `new_money`, `type`, `status`, `remark`, `gtime`) VALUES ({$bh},'$j',{$arr[0]['money']},$n,1,3,'上分',".time()." )";
            $sql3="INSERT INTO `wx_trigers`(`ct`, `flag`, `gtime`) VALUES ('$str',0,".time().")";
            if($db->U_D($sql1) && $db->add($sql2) && $db->add($sql3)){
                $db->U_D('COMMIT');
                die("上分成功.上分金额：$j");
            }else{
                $db->U_D('ROLLBACK');
                die("上分失败，请重试");
            }
        }elseif($u==2){
            $db->U_D('START TRANSACTION');
            $n=$arr[0]['money']-$j;
            if($n<0){
                die("用户点数不够，下分失败。");
            }
            $str="玩家「{$arr[0]['nickname']}」下分已到账，请注意查看余额，谢谢！";
            $sql1="UPDATE `wx_manage` SET `money`=$n WHERE ID=$bh";
            $sql2="INSERT INTO `user_log`(`uid`, `money`, `old_money`, `new_money`, `type`, `status`, `remark`, `gtime`) VALUES ({$bh},'$j',{$arr[0]['money']},$n,2,4,'下分',".time()." )";
            
            $sql3="INSERT INTO `wx_trigers`(`ct`, `flag`, `gtime`) VALUES ('$str',0,".time().")";
            
            if($db->U_D($sql1) && $db->add($sql2) && $db->add($sql3)){
                $db->U_D('COMMIT');
                die("下分成功.下分金额：$j");
            }else{
                $db->U_D('ROLLBACK');
                die("下分失败，请重试");
            }
        
        }
         
        
        
    }
        
    public function cmoney(){
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $num = 10;
        //echo $_GET['un'];
        $uid=$this->userid($db,$_GET['un']);
        
        if($_GET['un']){$uid=$uid?$uid:10000000;}
        $type=$_GET['tp'];
        $status=$_GET['st'];
        $remark=$_GET['rk'];
        $data1 = $_GET['s1'] ? strtotime($_GET['s1']) : 0;
        $data2 = $_GET['s2'] ? strtotime($_GET['s2']) + 3600 * 24 : time();
        $sql="select a.*,b.nickname as name from user_log a ,wx_manage b where a.uid=b.ID and (a.gtime between $data1 and $data2) ";
        if($uid){$sql.="and a.uid=$uid ";}
        if($type){$sql.="and a.type=$type ";}
        if($status){$sql.="and a.status=$status ";}
        if($remark){$sql.="and a.remark like '%$remark%' ";}
        $sql.= ' order by a.ID desc limit ' . ($p - 1) * $num . ', ' . $num;
       // echo $sql;
        $data=$db->select($sql);
        $countsql = "select count(ID) as nu from user_log where (gtime between $data1 and $data2) ";
        if($uid){$countsql.="and uid=$uid ";}
        if($type){$countsql.="and type=$type ";}
        if($status){$countsql.="and status=$status ";}
        if($remark){$countsql.="and remark like '%$remark%' ";}
        $coutdata=$db->select($countsql);
        foreach ($data as $key=>$value){$data[$key]['status']=$GLOBALS['C']['LX'][$data[$key]['status']];}
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    public function userid($db,$name)
    {
        $this->cuser();
        if($name){
            $sql="select * from `wx_manage` where nickname='$name'";
            $arr=$db->select($sql);
            return $arr[0]['ID'];
        }else{
            return 0;
        }
        
       
    }
    
    public function bl()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $arr=$db->select("SELECT * FROM `wx_systemset` where ID=1");

        $this->assign('arr',json_decode($arr[0]['pkbl'],true));
        $this->display();;
    }
    
    public function setbl(){
        $this->cuser();
        $str=$_POST['j'];
        
        $array=explode("|",$str);
        $arr=array();
        foreach ($array as $k=>$v)
        {
            $key=explode('-',$v);
            $arr[$key[0]]=$key[1];
        }
        
       
        $str=json_encode($arr,JSON_UNESCAPED_UNICODE);
       
        $db=new dbli($GLOBALS['C']);
        $sql="UPDATE `wx_systemset` SET `pkbl`='$str' WHERE ID=1";
        if($db->U_D($sql)){
            
             die('倍率修改成功');
        }else{
            die('倍率修改失败');
        }
    }
    
    
    public function setfp()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $arr=$db->select("SELECT * FROM `wx_systemset` where ID=1");
        $this->assign('arr',$arr[0]['fp']);
        $this->display();
    }
    
    public function upfp()
    {
        $this->cuser();
        $str=intval($_POST['t']);
        $db=new dbli($GLOBALS['C']);
        
        $arr=$db->select("SELECT * FROM `wx_systemset` where ID=1");
        
        $date1=strtotime(date('Y-m-d',time()));
        $date2=strtotime(date('Y-m-d',time()).' 23:59:59');
        
        $db->U_D('START TRANSACTION');
        $sql="UPDATE `wx_systemset` SET `fp`='$str' WHERE ID=1";
        $sql2="UPDATE `wx_pkd` SET `fp`=fp+{$arr[0]['fp']}-$str WHERE oktime BETWEEN $date1 and $date2";
        
        if($db->U_D($sql) && $db->U_D($sql2)){
            $db->U_D('COMMIT');
            die('修改成功');
        }else{
            $db->U_D('ROLLBACK');
            die('修改失败');
        }
    }
    
    public function tj()
    {
        $this->cuser();
      
        $db = new dbli($GLOBALS['C']);
        $t = $_GET['t'] ? $_GET['t'] : 0;
        $time=$_GET['time'] ? strtotime($_GET['time']) : 0;
        
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        
        $num = 10;
        $sql = "select * from `wx_issus_TJ` where 1=1";
        if($t){$sql.= " and qh='$t'";}
        if($time>0){
            $time2=$time+3600*24;
            $sql.=" and (gtime between $time and $time2)";
            
        }else{
            $time2=time();
            $sql.=" and (gtime between $time and $time2)";
        }
        
        
        $sql .= ' order by ID desc limit ' . ($p - 1) * $num . ', ' . $num;
        $data = $db->select($sql);
        
        $countsql = "select count(ID) as nu from `wx_issus_TJ` where 1=1 ";
        if($t){$countsql.= " and qh='$t'";}
        if($time>0){
            $time2=$time+3600*24;
            $countsql.=" and (gtime between $time and $time2)";
        
        }else{
            $time2=time();
            $countsql.=" and (gtime between $time and $time2)";
        }
        $coutdata = $db->select($countsql);
        
        if(!$t){
            if($time>0){
                $this->assign('timef',$this->settj($time,$time2));
            }else{
                $this->assign('timef',$this->settj(strtotime(date('Y-m-d'))-3600*24,strtotime(date('Y-m-d').' 23:59:59')-3600*24));
            }  
        }
        
        
        
        
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
        $this->diplay();
    }
    
    public function wel()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $res=$db->select("select count(ID) as mx from wx_manage");
        $this->assign('count',$res[0]['mx']);
        $this->assign('first',$this->settj(0,time()));
        $this->assign('first2',$this->settj(strtotime(date('Y-m-d')),strtotime(date('Y-m-d').' 23:59:59')));
        $this->assign('first3',$this->settj(strtotime(date('Y-m-d'))-3600*24,strtotime(date('Y-m-d').' 23:59:59')-3600*24));
        $this->assign('first4',$this->settj(strtotime(date('Y-m-d'))-3600*24*2,strtotime(date('Y-m-d').' 23:59:59')-3600*24*2));
        
        $this->display();
    }
    
    protected function settj($time1,$time2)
    {
        $total=0;
        $db=new dbli($GLOBALS['C']);
        $sql2="SELECT `type`,`money`,`status` FROM `user_log` where gtime between $time1 and $time2";
        $arr=$db->select($sql2);
        foreach ($arr as $v)
        {
            if($v['status']==1 || $v['status']==2){
               // echo 'aa';
                $v['type']==1?$total-=$v['money']:$total+=$v['money'];
            }
            if($v['status']==3 || $v['status']==4){
                $v['type']==1?$total+=$v['money']:$total-=$v['money'];
            }
        }
        
        $sql2="select sum(money) as m from `user_log` where (gtime between $time1 and $time2) and status=3";
        $arr2=$db->select($sql2);
        
        $sql2="select sum(money) as m from `user_log` where (gtime between $time1 and $time2) and status=4";
        $arr3=$db->select($sql2);
        
        $sql2="select sum(money) as m from `user_log` where (gtime between $time1 and $time2) and status=1";
        $arr4=$db->select($sql2);
        
        $sql2="select sum(money) as m from `user_log` where (gtime between $time1 and $time2) and status=2";
        $arr5=$db->select($sql2);
        
        return array($total,$arr2[0]['m'],$arr3[0]['m'],$arr4[0]['m'],$arr5[0]['m']);
    }
    
    
    public function tongjitianshu()
    {
        //计算昨天的统计
        $db=new dbli($GLOBALS['C']);
        $time1=strtotime(date('Y-m-d'))-3600*24;
        $time2=strtotime(date('Y-m-d').' 23:59:59')-3600*24;
        $arr=$db->select("select * from `user_log` where (gtime between $time1 and $time2) and (status=1 or status=2)");
        $dats=array();
        foreach ($arr as $v)
        {
            $flag=false;
            foreach ($dats as $k=>$vm)
            {
                if($k==$v['issue'])
                {
                    $flag=true;
                }
            }
           if($flag)
           {
               if($v['status']==1){
                   $dats[$v['issue']][0]+=$v['money'];
               }elseif($v['status']==2){
                   $dats[$v['issue']][1]+=$v['money'];
               }
               
           }else{
               if($v['status']==1){
                   $dats[$v['issue']]=array($v['money'],0);
                }elseif($v['status']==2){
                    $dats[$v['issue']]=array(0,$v['money']);
               }
           }
            
        }
        
    
      if($dats){
          $sql="INSERT INTO `wx_issus_TJ`(`qh`, `xz`, `zj`, `gtime`) VALUES";
          $times=time()-3600*24;
          foreach ($dats as $k=>$v)
          {
              $sql.="  ('$k',{$v[0]},{$v[1]},$times),";
          }
          $sql=substr($sql,0,strlen($sql)-1);
          $db->add($sql);
      }
       
        
      
    }
    
    
    
    public function gb()
    {
        $this->cuser();
        
        
        
        $this->display();
    }
    
    public function  hy()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select * from wx_hy where tg=1";
        $arr= $db->select($sql);
        $this->assign('hy',$arr);
        $this->display();
        
    }
    
    
    public function ds()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select * from wx_hy where tg=2";
        $arr= $db->select($sql);
        $this->assign('hy',$arr);
        $this->display();
    }
    
    public function sethy()
    {
        $this->cuser();
        $tg=$_POST['tg'];
        $ct=$_POST['ct'];
        $db=new dbli($GLOBALS['C']);
        $sql="INSERT INTO `wx_hy`( `ct`, `tg`) VALUES ('$ct',$tg)";
        if($tg==1){
            $url="/?G=admin/hy";
        }else if($tg==2){
            $url="/?G=admin/ds";
        }
        
        if($db->add($sql)){
            $this->assign('message','添加成功。');
            $this->assign('url',$url);
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','添加失败。');
            $this->assign('url',$url);
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    public function delhy()
    {
        $this->cuser();
        $id=$_GET['i'];
        $tg=$_GET['t'];
        $db=new dbli($GLOBALS['C']);
        $sql="DELETE FROM `wx_hy` WHERE id='$id'";
        if($tg==1){
            $url="/?G=admin/hy";
        }else if($tg==2){
            $url="/?G=admin/ds";
        }
        if($db->U_D($sql)){
            $this->assign('message','成功。');
            $this->assign('url',$url);
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','失败。');
            $this->assign('url',$url);
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    public function gz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select * from `wx_systemset` where ID=1";
        $ct=$db->select($sql);
        $this->assign('ct',$ct[0]['ct']);
        $this->display();
    }
    
    public function setgz()
    {
        $this->cuser();
        $htmlData = '';
        if(!empty($_POST['content'])) {
            if (get_magic_quotes_gpc()) {
                $htmlData = stripslashes($_POST['content']);
            } else {
                $htmlData = $_POST['content'];
            }
        }
        $htmlData = $_POST['content'];
        $db=new dbli($GLOBALS['C']);
        
        $sql="update wx_systemset set ct='$htmlData' where ID=1";

        if($db->U_D($sql)){
           $this->assign('message','成功。');
            $this->assign('url','/?G=admin/gz');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            echo $sql;
        }
    }
    
    
    public function kefu()
    {
        $this->cuser();
        
        $this->display();
    }
    
    public function ustatus()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select distinct a.senderID,b.headpic,b.nickname from wx_kf a,wx_manage b where a.senderID=b.ID";
        $arr=$db->select($sql);
        
        foreach ($arr as $k=>$v)
        {
            $sql="select count(ID) as n from wx_kf where `senderID`={$v['senderID']} and flag=0";
            $count=$db->select($sql);
            $arr[$k]['count']=$count[0]['n'];
        }
        
        echo json_encode($arr);
    }
    
    public function umessage()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $id=is_numeric($_POST['id'])?$_POST['id']:0;
        $sql="select * from  wx_kf where senderID=$id or toID=$id order by ID asc";
        $arr=$db->select($sql);
       
        $sql="update wx_kf set flag=1 where senderID='$id'";
        file_put_contents('/t.txt',$sql);
        $db->U_D($sql);
        foreach ($arr as $k=>$v)
        {
            $arr[$k]['gtime']=date('Y-m-d H:i:s',$v['gtime']);
        }
        echo json_encode($arr);
    }
    public function kfgz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select * from wx_kf_gz";
        $this->assign('arr',$db->select($sql));
        $this->display();
    }
    
    public function setkfgz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $k=htmlspecialchars($_POST['k']);
        $ct=htmlspecialchars($_POST['ct']);
        $sql="INSERT INTO `wx_kf_gz`( `k`, `ct`, `gtime`) VALUES ('$k','$ct',".time().")";
        if($db->add($sql)){
            $this->assign('message','添加成功。');
           
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','添加失败。');
           
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    
    public function delkfgz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $id=is_numeric($_GET['i'])?$_GET['i']:0;
        $sql="DELETE FROM `wx_kf_gz` WHERE `ID`=$id";
        
        if($db->U_D($sql)){
            $this->assign('message','成功。');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','失败。');
            $this->assign('time','3');
            $this->display('jump');
        }
        
    }
    
    public function  mntz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $arr1=$db->select('select * from wx_jqr where t=1');
        $this->assign('arr1',$arr1);
        $arr2=$db->select('select * from wx_jqr where t=2');
        $this->assign('arr2',$arr2);
        
        
        $arr3=$db->select('select * from wx_systemset where ID=1');
        $this->assign('arr3',$arr3);
        
        $this->display();
    }
    
    public function deljqr(){
        $this->cuser();
        $i=is_numeric($_GET['i'])?$_GET['i']:0;
        $db=new dbli($GLOBALS['C']);
        if($db->U_D("DELETE FROM `wx_jqr` WHERE ID=$i")){
            $this->assign('message','成功。');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','失败。');
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    public function setjqr(){
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $t=is_numeric($_POST['t'])?$_POST['t']:0;
        $o=is_numeric($_POST['o'])?$_POST['o']:0;
        if($db->U_D("UPDATE `wx_systemset` SET `jq_on`=$o,`jq_time`=$t WHERE ID=1")){
            die('保存成功');
        }else{
            die('保存失败');
        }
        
    }
    
    public function addjqr()
    {
        $this->cuser();
        $this->display();
    }
    
    public function updatejqr()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $pt='';
        if($_FILES["pic"]){
            $pt="/public/upload/".time().$_FILES["pic"]["name"];
            $pt1=$_SERVER['DOCUMENT_ROOT'].$pt;
            move_uploaded_file($_FILES["pic"]["tmp_name"],$pt1);
        }
        $ct=htmlspecialchars($_POST['ct']);
        $t=$_POST['t'];
         $sql="INSERT INTO `wx_jqr`( `pic`, `ct`, `t`, `gt`) VALUES ('$pt','$ct',$t,".time().")";
           if($db->add($sql)){
               $this->assign('message','成功。');
               $this->assign('time','3');
               $this->display('jump');
            }else{
                   $this->assign('message','失败。');
                   $this->assign('time','3');
                   $this->display('jump');
           }
        
    }
    
    
    
    public function cz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select * from `wx_systemset` where ID=1";
        $ct=$db->select($sql);
        $this->assign('ct',$ct[0]['cz']);
        $this->display();
    }
    
    public function setcz()
    {
        $this->cuser();
        $htmlData = '';
        if (! empty($_POST['content'])) {
            if (get_magic_quotes_gpc()) {
                $htmlData = stripslashes($_POST['content']);
            } else {
                $htmlData = $_POST['content'];
            }
        }
        $db=new dbli($GLOBALS['C']);
    
        $sql="update wx_systemset set cz='$htmlData' where ID=1";
        if($db->U_D($sql)){
           $this->assign('message','成功。');
            $this->assign('url','/?G=admin/cz');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            echo $sql;
        }
         
        
    }
    
    
    public function kj()
    {
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $qh = $_GET['qh'] ? $_GET['qh'] : 0;
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        
        $yx=$_GET['yx']?$_GET['yx']:1;
        
        $time1=$_GET['time1']?strtotime($_GET['time1']):0;
        $time2=$_GET['time2']?strtotime($_GET['time2'])+3600*24:time();

        $num = 10;
        $sql = "select * from `pks_k` where 1=1";
        $countsql = "select count(ID) as nu from `pks_k` where 1=1 ";

        if($qh){
            $sql.= " and  issue='$qh'";
            $countsql.=" and  issue='$qh'";
        }
        if($yx){
            $sql.= " and  games='$yx'";
            $countsql.=" and  games='$yx'";
        }
        $sql .=" and (gtime between $time1 and $time2 )";
        $countsql .=" and (gtime between $time1 and $time2 )";
        
        
        $sql .= ' order by gtime desc limit ' . ($p - 1) * $num . ', ' . $num;
       
        $data = $db->select($sql);

        $coutdata = $db->select($countsql);
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    public function xzls()
    {
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $qh = $_GET['qh'] ? $_GET['qh'] : 0;
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $yx=$_GET['yx']?$_GET['yx']:1;
        $time1=$_GET['time1']?strtotime($_GET['time1']):0;
        $time2=$_GET['time2']?strtotime($_GET['time2'])+3600*24:time();
       
        $status=$_GET['status'];
        $name=$_GET['name'];
        $uid=$this->userid($db, $name);
        $uid=$uid>0?$uid:100000000000;
        $num = 10;
        $sql = "select a.*,b.nickname from `wx_pk10` a,`wx_manage` b where 1=1";
        $countsql = "select count(ID) as nu from `wx_pk10` where 1=1 ";
        
        if($status){
            $sql.= " and  a.is_money='$status'";
            $countsql.=" and  is_money='$status'";
        }
        
        if($name){
            $sql.= " and  a.uid='$uid'";
            $countsql.=" and  uid='$uid'";
        }
        
        
        if($qh){
            $sql.= " and  a.issue='$qh'";
            $countsql.=" and  issue='$qh'";
        }
        if($yx){
            $sql.= " and  a.games='$yx'";
            $countsql.=" and  games='$yx'";
        }
        $sql .=" and (a.gtime between $time1 and $time2 )";
        
        
        $sql .=" and a.uid=b.ID ";
         
        
        $countsql .=" and (gtime between $time1 and $time2 )";
        
        
        $sql .= ' order by a.gtime desc limit ' . ($p - 1) * $num . ', ' . $num;
         //echo $sql;
        $data = $db->select($sql);
        
        $coutdata = $db->select($countsql);
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
        
    }
    
    public function daili()
    {
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $t = $_GET['name'] ? $_GET['name'] : 0;
        $mark= $_GET['m'] ? $_GET['m'] : 0;
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $num = 10;
        $sql = "select * from `wx_daili` where 1=1";
        $countsql = "select count(ID) as nu from `wx_daili` where 1=1 ";
        
        if($t){
            $sql.=" and name='$t'";
            $countsql.=" and name='$t'";
        }
        if($mark){
            $sql.=" and mark like '%$mark%' ";
            $countsql.="and mark like '%$mark%' ";
        }
        
        $sql .= ' order by ID desc limit ' . ($p - 1) * $num . ', ' . $num;
       
        
        $data = $db->select($sql);
        $coutdata = $db->select($countsql);
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    public function dlls()
    {
        $this->cuser();
        $db = new dbli($GLOBALS['C']);
        $data1 = $_GET['s1'] ? strtotime($_GET['s1']) : 0;
        $data2 = $_GET['s2'] ? strtotime($_GET['s2']) + 3600 * 24 : time();
        $t = $_GET['i'] ? $_GET['i'] : 0;
        $arr=$db->select("select * from wx_manage where dlID=$t");
        $k1=0;
        $k2=0;
        $k3=0;
        $k4=0;
        foreach ($arr as $key=>$value)
        {
            
          $sql="select sum(money) as u from user_log where status=2 and uid={$value['ID']} and (gtime between $data1 and $data2)";  
          $x1=$db->select($sql);
          $arr[$key]['zj']=$x1[0]['u']?$x1[0]['u']:0;
          $k1+=$arr[$key]['zj'];
          
          $sql="select sum(money) as u from user_log where status=1 and uid={$value['ID']} and (gtime between $data1 and $data2) and dit=0";
          $x1=$db->select($sql);
          $arr[$key]['ed']=$x1[0]['u']?$x1[0]['u']:0;
          $k2+=$arr[$key]['ed'];
          
          $sql="select sum(money) as u from user_log where status=3 and uid={$value['ID']} and (gtime between $data1 and $data2) ";
          $x1=$db->select($sql);
          $arr[$key]['sf']=$x1[0]['u']?$x1[0]['u']:0;
          $k3+=$arr[$key]['sf'];
          
          
          $sql="select sum(money) as u from user_log where status=4 and uid={$value['ID']} and (gtime between $data1 and $data2) ";
          $x1=$db->select($sql);
          $arr[$key]['xf']=$x1[0]['u']?$x1[0]['u']:0;
          $k4+=$arr[$key]['xf'];
          
        }
        $array=array(
            count($arr),
            $k2,
            $k1,
            $k3,
            $k4
        );
        $this->assign('zt',$array);
        $this->assign('arr',$arr);
        $this->display();
    }
    
    public function dlkhxz()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $p = $_GET['p'] ? intval($_GET['p']) : 1;
        $num = 10;
        $status=$_GET['st'];
        $data1=$_GET['s1']!=0?strtotime($_GET['s1']):0;
        $data2=$_GET['s2']?strtotime($_GET['s2']." 23:59:59"):time();
        $id=$_GET['i'];
        $sql="select a.*,b.nickname as name from user_log a ,wx_manage b where  a.uid=$id and a.uid=b.ID and (a.gtime between $data1 and $data2) ";
        $countsql = "select count(ID) as nu from user_log where (gtime between $data1 and $data2) and uid=$id ";
        if($status){$sql.="and a.status=$status ";$countsql.=" and status=$status ";}
        $sql.= ' order by a.ID desc limit ' . ($p - 1) * $num . ', ' . $num;
        $data=$db->select($sql);
        $coutdata=$db->select($countsql);
        foreach ($data as $key=>$value){$data[$key]['status']=$GLOBALS['C']['LX'][$data[$key]['status']];}
        $this->assign('arr', $data);
        $this->assign('count', $coutdata[0]['nu']);
        $this->assign('p', $p);
        $this->display();
    }
    
    public function adddaili()
    {
        $this->cuser();
        $this->display();
    }
    
    public function updaili()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        
        $this->assign('arr',$db->select("select * from wx_daili where ID={$_GET['i']}"));
        $this->display();
    }
    
    public function upxtdl()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $name=htmlspecialchars($_POST['name']);
        $pass=htmlspecialchars($_POST['pass']);
        $mark=htmlspecialchars($_POST['mark']);
        $i=$_POST['i'];
        $sql="update wx_daili set name='$name',mark='$mark'";
        
        if($pass){
            $sql.=" ,pass='".md5($pass)."'";
        }
        $sql.=" where ID=$i ";
       // echo $sql;exit;
        if($db->U_D($sql)){
            $this->assign('message',"修改成功！");
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','修改失败！');
            $this->assign('time','3');
            $this->display('jump');
        }
        
    }
    
    public function delxzdl()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $i=$_GET['i'];
        $sql="DELETE FROM `wx_daili` WHERE ID=$i";
        if($db->U_D($sql)){
            $this->assign('message',"修改成功！");
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','修改失败！');
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    public function addxtdl()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $name=htmlspecialchars($_POST['name']);
        $pass=htmlspecialchars($_POST['pass']);
        $pass2=htmlspecialchars($_POST['pass2']);
        $mark=htmlspecialchars($_POST['mark']);
        
        
        if($pass!=$pass2 || $pass=='' || $name==''){
            $this->assign('message','重复密码不一致或资料为空');
            $this->assign('time','3');
            $this->display('jump');
        }
        $pass=md5($pass);
        $sql="INSERT INTO `wx_daili`(`name`, `pass`, `mark`,  `gtime`) VALUES ('$name','$pass','$mark',".time().")";
        if($db->add($sql)){
            $this->assign('message','开通成功 开通账号为：'.$name."<br/>密码为：$pass2");
            $this->assign('time','3');
            $this->display('jump');
        }else{
            $this->assign('message','开通失败，请检查账户名是否存在！');
            $this->assign('time','3');
            $this->display('jump');
        }

    }
    
    public function xfdd()
    {
        $this->cuser();
        $t=$_GET['type'];
        $db=new dbli($GLOBALS['C']);
        $sql="SELECT * FROM `wx_udcount` WHERE `type`=$t and status=1";
        $this->assign('arr',$db->select($sql));
        $this->display();
    }
    
    public function uppdd()
    {
        $this->cuser();
        $id=$_GET['i'];
        $type=$_GET['type'];
        $bh=$_GET['uid'];
        $j=intval($_GET['money']);
        $db=new dbli($GLOBALS['C']);
        $sql="select * from wx_manage where ID=$bh";
        $arr=$db->select($sql);
        
        if(!$arr){
            $this->assign('message','玩家不存在');
            $this->assign('time','3');
            $this->display('jump');
            die();
        }
        if($type==1){
            $str="玩家「{$arr[0]['nickname']}」上分已受理，请注意查看点数，谢谢！";
            $n=$arr[0]['money']+$j;
            $db->U_D('START TRANSACTION');
            $sql1="UPDATE `wx_manage` SET `money`=$n WHERE ID=$bh";
            $sql2="INSERT INTO `user_log`(`uid`, `money`, `old_money`, `new_money`, `type`, `status`, `remark`, `gtime`) VALUES ({$bh},'$j',{$arr[0]['money']},$n,1,3,'上分',".time()." )";
            $sql3="INSERT INTO `wx_trigers`(`ct`, `flag`, `gtime`) VALUES ('$str',0,".time().")";
            $sql4="UPDATE wx_udcount set status=3 where ID=$id";
            
            if($db->U_D($sql1) && $db->add($sql2) && $db->add($sql3) && $db->U_D($sql4)){
                $db->U_D('COMMIT');
                
                $this->assign('message',"上分成功.上分金额：$j");
                $this->assign('time','3');
                $this->display('jump');
                die();
                
            }else{
                $db->U_D('ROLLBACK');
               
                $this->assign('message',"上分失败，请重试");
                $this->assign('time','3');
                $this->display('jump');
                die();
            }
        }elseif($type==2){
            $db->U_D('START TRANSACTION');
            $n=$arr[0]['money']-$j;
            $sql1="UPDATE `wx_manage` SET `money`=$n WHERE ID=$bh";
            $sql2="INSERT INTO `user_log`(`uid`, `money`, `old_money`, `new_money`, `type`, `status`, `remark`, `gtime`) VALUES ({$bh},'$j',{$arr[0]['money']},$n,2,4,'下分',".time()." )";
            
            $sql4="UPDATE wx_udcount set status=3 where ID=$id";
            
            
            if($db->U_D($sql1) && $db->add($sql2) && $db->U_D($sql4)){
                $db->U_D('COMMIT');
                $this->assign('message',"下分成功.下分金额：$j");
                $this->assign('time','3');
                $this->display('jump');
                die();
            }else{
                $db->U_D('ROLLBACK');
                $this->assign('message',"下分失败，请重试");
                $this->assign('time','3');
                $this->display('jump');
                die();
            }
        
        }
    }
    
    public function jujuesx()
    {
        $this->cuser();
        $id=$_GET['i'];
        $db=new dbli($GLOBALS['C']);
        $sql4="UPDATE wx_udcount set status=3 where ID=$id";
        if($db->U_D($sql4)){
            $this->assign('message',"拒绝成功，此订单将不再出现");
            $this->assign('time','3');
            $this->display('jump');
           
        }else{
             
                $this->assign('message',"拒绝失败，请重试。");
                $this->assign('time','3');
                $this->display('jump');
             
       }
    }
    
    public function checkStatus()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="select count(ID) as u from `wx_udcount` where type=2 and status=1";
        $sql_Two="select count(ID) as u from `wx_udcount` where type=1 and status=1";
        $sql_t="SELECT count(ID) as num  FROM `wx_kf` where flag=0 and senderID<>'k'";
        $result=$data=$db->select($sql);
        $result_Two=$data=$db->select($sql_Two);
        $result_t=$data=$db->select($sql_t);
        if($result[0]['u']>0 || $result_Two[0]['u']>0 || $result_t[0]['num']>0){
            die($result_Two[0]['u'].'-'.$result[0]['u'].'-'.$result_t[0]['num']);
        }
        die('1');
    }
    
    public function selfOpen()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $this->display();
    }
    
    public function setUserData()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $sql="SELECT * FROM `wx_pkd` WHERE `kp` < unix_timestamp(now()) order by `ID` desc limit 0,1";
        $issueData=$db->select($sql);
        
        $issueData[0]['oktime']=date('Y-m-d H:i:s',$issueData[0]['oktime']);
        
        $sql="SELECT SUM(money) as money,`stype`,`nums` FROM `wx_pk10` WHERE `issue`='{$issueData[0]['issue']}' group by `stype`,`nums`";
        $UserData=$db->select($sql);
        $UserData['qh']=$issueData[0];
        echo json_encode($UserData);
    }
    
    
    
    public function handOpen()
    {
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/openpk.php';
        include_once $_SERVER['DOCUMENT_ROOT'].'/Pmodel/openft.php';

        $db=new dbli($GLOBALS['C']);
        $sql="SELECT `pkbl` FROM `wx_systemset` WHERE ID=1";
        $resl=$db->select($sql);
        $array=json_decode($resl[0]['pkbl'],true);
        
        $data=array(
            'qh'=>$_POST['qh'],
            'jg'=>$_POST['jg'],
            'time'=>$_POST['time']
        );
        
        
        if($_POST['game']==1){
            $openpk=new openpk($GLOBALS['C'],$data,$array);
            $openpk->oneOpen();
        }else{
            $openft=new openft($GLOBALS['C'],$data,$array);
            $openft->oneOpen();
        }
        echo PHP_EOL.'开奖完毕'.PHP_EOL;
        
    }
    
    
    public function shutOpen()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $this->assign('arr',$db->select('select * from wx_pkd where oktime>'.time()));
        $this->display();
    }
    
    public function openshand()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        $t=$_GET['t'];
        $i=$_GET['i'];
       if($db->U_D("update wx_pkd set isauto=$t where ID=$i")){
            $this->assign('message','修改成功');
            $this->assign('time','3');
            $this->display('jump');
        }else{
            
            $this->assign('message','修改失败');
            $this->assign('time','3');
            $this->display('jump');
        }
    }
    
    
    public function mima()
    {
        $this->display();
    }
    
    public function upmima()
    {
        $this->cuser();
        $db=new dbli($GLOBALS['C']);
        //$name=htmlspecialchars($_POST['name']);
        $pass=htmlspecialchars($_POST['pass']);
        $passd=htmlspecialchars($_POST['passd']);
        if($pass!=$passd){
            $this->assign('message',"重复密码错误！.");
            $this->assign('time','3');
            $this->display('jump');
            die();
        }
        $i=$_SESSION['u']['id'];
      
        $sql="update wx_admin set ";
    
        if($pass){
            $sql.=" pass='".md5($pass)."'";
        }else{
            $this->assign('message',"密码不能为空！");
            $this->assign('time','3');
            $this->display('jump');
            die();
        }
        $sql.=" where ID=$i ";
        //echo $sql;exit;
        if($db->U_D($sql)){
            $this->assign('message',"修改成功！");
            $this->assign('time','3');
            $this->display('jump');
        }else{
          
            $this->assign('message','修改失败！');
            $this->assign('time','3');
            $this->display('jump');
        }
    
    }
    
}


?>